import request from "@/utils/request"

const url = '/oAddressBook'

// 获取当前用户的所有地址
export function getOwnAddressAPI() {
    return request({
        url: `${url}/findAllAddr`
    })
}

// 将地址设为默认地址
export function setDefaultAPI(addrId) {
    return request({
        url: `${url}/isDefault`,
        params: {
            addrId
        }
    })
}

// 根据id获取地址
export function getAddressByIdAPI(id) {
    return request({
        url: `${url}/findById`,
        params: {
            id
        }
    })
}

// 删除地址
export function delAddressAPI(addrId) {
    return request({
        url: `${url}/delete`,
        method: 'DELETE',
        params: {
            addrId
        }
    })
}

// 添加地址
export function addAddressAPI({ consignee, detail, phone, isDefault }) {
    return request({
        url: `${url}/addAddress`,
        method: 'POST',
        data: {
            consignee,
            detail,
            phone,
            isDefault
        }
    })
}

// 编辑地址
export function updateAddressAPI({ addrId, consignee, detail, phone, isDefault  }) {
    return request({
        url: `${url}/updateAddress`,
        method: 'POST',
        data: {
            addrId,
            consignee,
            detail,
            phone,
            isDefault
        }
    })  
}

// 为购物车获取地址
export function getCartListAddressAPI() {
    return request({
        url: `${url}/setAddr`
    })
}